let _data = {};
//用于全局事件统一分发。。需人为控制事件订阅风暴
class Bus{
    constructor(){
        this._bus = new cc.Node("eventBus");
        this._data = _data;
    }

    on( name , handler , scope ){
        if(scope) {
            handler = handler.bind(scope);
        }
        this._bus.on( name , handler );
    }

    once( name , handler , scope ){
        if(scope) {
            handler = handler.bind(scope);
        };
        this._bus.once( name , handler );
    }

    off( name , handler , scope ){
        this._bus.off( name , handler );
    }

    emit( name , p ){
        let event =  new cc.Event.EventCustom( name ,false ) ;
        p && event.setUserData(p);
        this._bus.dispatchEvent ( event );
    }
}

module.exports = Bus; 